<?php

/******************************************************************************	
*
*	This file is part of Perfect Auth Class.
*
*    Perfect Auth Class is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    Perfect Auth Class is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with Perfect Auth Class; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*	
*******************************************************************************/

// class.auth.php - Test File

include "class.pauth.php";

$auth = new pauth(60,"/path/to/class/","/"); // 60 seconds -> time to expire the session
$login = "loginhere";
$senha = "passhere";


if(empty($_GET['page'])){
	
	$auth-> testLogin("central"); //test if logged, but don't give error
	
	if(empty($auth-> user['login'])){
		
		echo "Hello Guest";
	}
	else {
		
		echo "Hello ".$auth-> user['login'];
	}
	
	echo "<form action=\"?page=login\" method=\"POST\">
		Login: <input type=\"text\" name=\"login\" size=\"10\" maxlength=\"10\"><br>
		Senha: <input type=\"password\" name=\"senha\" size=\"10\" maxlength=\"10\"><br>
		<input name=\"btn_logar\" value=\"Logar\" type=\"submit\"><br>
		<a href=\"?page=logout\">Logout</a>
		</form>";

}

elseif($_GET['page']=="login"){
	
	if($_POST['login'] == $login and $_POST['senha'] == $senha){
		
		$auth-> login($_POST['login'],"central");
		header("Location: ?page=secret");
		
	}
	else {
		$auth-> error("Login ou Senha Incorreto!");
	}

}

elseif($_GET['page']=="secret"){
	
	$auth-> validate("central"); //validate if logged
	$auth-> testLogin("central"); //test if logged but don't give error
	
	echo "Hello ".$auth-> user['login']."<br>";
	echo "Login Ok! Next Test: <a href=\"?page=final\">next</a><br>";
	echo "Go to <a href=\"?page=admin\">admin</a> (you need to be logged as admin).";
	
}

elseif($_GET['page']=="final"){
	
	$auth-> validate("central");
	
	echo "Logged!"; //test if the user as logged
	
}

elseif($_GET['page']=="admin"){
	
	$auth-> validate("admin");
	
	echo "Logged!"; //test if the user as logged as admin

}

elseif($_GET['page']=="logout"){

	$auth-> logout("central"); //use $auth-> logout("section"); to logout
	
	echo "Logout";
}

?>
